package com.hg.hggood.config;

import com.hg.hggood.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**处理器拦截器的注册*/
@Configuration //加载当前的拦截器并进行注册
public class LoginInterceptorConfigurer implements WebMvcConfigurer {
    /**配置拦截器*/
    public void addInterceptors(InterceptorRegistry registry){
        //创建自定义的拦截器对象
        HandlerInterceptor interceptor = new LoginInterceptor();
        //配置黑白名单:存放在一个List集合
        List<String> patterns = new ArrayList<>();
        //如果它目录下的所有内容都放行那就/**
//        patterns.add("/xregister");
        patterns.add("/xlogin");
//
//        patterns.add("/users/reg");
//        patterns.add("/users/login");
//        patterns.add("/users/change_password");
//        patterns.add("/users/change_avatar");
//        patterns.add("/users/products/**");
//        patterns.add("/users/districts/**");


        //完成拦截器的注册
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**")//表示要拦截的url是什么
                .excludePathPatterns(patterns);
        System.out.println(patterns+"%%%%");
    }
}
